package HLA2.control;



import hla.rti.RTIexception;
public class GestioneDischi {

	private Simulatore2 s;

	public GestioneDischi(Simulatore2 s){
		this.s = s;
	}
	public void gestisciDisk1(int i) throws RTIexception {


		s.disk1.occupato = false;
		//devo mandare la i
		s.simulazione.mandaJob(s.simulazione.objectHandle, "cpu", i);
//		*********************************************************************
//		System.out.println("GestisciFineDisk1: mandajob "+s.simulazione.fedamb.job);
//		*********************************************************************
		s.simulazione.advanceTime(1.0);
//		*********************************************************************
//		System.out.println("TEMPO FEDERAZIONE "+s.simulazione.fedamb.federateTime);
//		*********************************************************************

		if(!s.disk1.coda.isEmpty()){
//			*********************************************************************
//			System.out.println("GestisciFineDisk1: avanzo il job in codaDisk1 mandando job ="+s.disk1.coda.get(0)+"  e tempo");
//			*********************************************************************
			s.disk1.occupato = true;
            double x = s.disk1.getGen().next();
            s.simulazione.mandaJob_Tempo(s.simulazione.objectHandle, "d1Coda", s.disk1.coda.get(0), x);
			s.simulazione.advanceTime(1.0);
//			*********************************************************************
//			System.out.println("TEMPO FEDERAZIONE "+s.simulazione.fedamb.federateTime);
//			*********************************************************************
			s.disk1.coda.remove(0);
		}

	}

    	public void gestisciDisk2(int i) throws RTIexception {

		s.disk2.occupato = false;
		//devo mandare la i
		s.simulazione.mandaJob(s.simulazione.objectHandle, "cpu", i);
//		*********************************************************************
//		System.out.println("GestisciFineDisk2: mandajob "+s.simulazione.fedamb.job);
//		*********************************************************************
		s.simulazione.advanceTime(1.0);
//		*********************************************************************
//		System.out.println("TEMPO FEDERAZIONE "+s.simulazione.fedamb.federateTime);
//		*********************************************************************

		if(!s.disk2.coda.isEmpty()){
			s.disk2.occupato = true;
//			*********************************************************************
//			System.out.println("GestisciFineDisk2: avanzo il job in codaDisk2 mandando job ="+s.disk2.coda.get(0)+"  e tempo");
//			*********************************************************************
			double x = s.disk2.getGen().next();
            s.simulazione.mandaJob_Tempo(s.simulazione.objectHandle, "d2Coda", s.disk2.coda.get(0), x );
			s.simulazione.advanceTime(1.0);
//			*********************************************************************
//			System.out.println("TEMPO FEDERAZIONE "+s.simulazione.fedamb.federateTime);
//			*********************************************************************
			s.disk2.coda.remove(0);
		}
	}

}